//
//  UIList.h
//  storm
//
//  Created by wangdi on 13-8-18.
//
//

#ifndef __storm__UIList__
#define __storm__UIList__

#include "UIPanel.h"

namespace storm
{
    class UIListItem;
    
    class UIList : public UIPanel
    {
    public:
        enum ItemID
        {
            ID_ITEM_BEGIN = 100,
        };
        enum ItemListType
        {
            ITEMLIST_FROMTOP,           // 锚点再顶部
            ITEMLIST_FROMBOTTOM,
            ITEMLIST_FROMLEFT,
            ITEMLIST_FROMRIGHT,
        };
    public:
        virtual void visit();
        virtual bool isContainsTouch(cocos2d::CCTouch *pTouch);
    public:
        CREATE_FUNC(UIList);
        static UIList *Create(cocos2d::CCSize s, ItemListType type = ITEMLIST_FROMTOP);
        void   InitState(ItemListType type, cocos2d::CCSize s);
        void   UpdateList();
        void   AddItem(UIListItem *pItem);
        void   InsertItem(UIListItem *pItem, int pos);
        void   RemoveItem(UIListItem *pItem);
        void   ResortItems();
        void   SetParentScale(float scale);
        std::list<UIListItem *> *Items() {return &m_listItems;}
        
        UIListItem *ItemByIndex(int index);
        UIListItem *ItemByTag(int tag);
        int         IndexByTag(int tag);
        
    public:
        void ItemTouchBegin(cocos2d::CCTouch *pTouch);
        void ItemTouchMove(cocos2d::CCTouch *pTouch);
        void ItemTouchEnd(cocos2d::CCTouch *pTouch);
    private:
        void OnRemoveItem();
        void UnfocusAll();
    private:
        UIList()
        : m_pActiveItem(NULL)
        , m_bTouchMoving(false)
        , m_itemSizeCount(0)
        , m_parentScale(1.0f)
        , m_bStopUpdate(false)
        {
            
        }
        
    private:
        ItemListType            m_type;
        std::list<UIListItem *> m_listItems;
        float                   m_itemSizeCount;
        float                   m_edgePos;
        float                   m_scale;
        float                   m_parentScale;
        cocos2d::CCLayer       *m_pLayList;
        bool                    m_bStopUpdate;
        float                   m_startTouchPos;
        
        cocos2d::CCPoint        m_ptLast;
        bool                    m_bAutoMoving;
        bool                    m_bTouchMoving;
        float                   m_curSpeed;
        
        float                   m_startPos;
        float                   m_curSize;
        UIListItem             *m_pActiveItem;
    };
}

#endif /* defined(__storm__UIList__) */
